var bsurl = require('../../../utils/baseUrl.js');
var netUtils = require('../../../utils/netUtils.js');
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    orders: [],
    limit: 6,
    offset: 0,
    scrollTop: 0
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    app.editTabBar(app.globalData.tabBar);

    this.requestGoods();
  },
  requestGoods: function () {
    var that = this;
    netUtils.sendRequest("seller/showGoods.do", {
      limit: this.data.limit,
      offset: this.data.offset,
    }, (data) => {
      console.log(that.data.limit)
      if (data.body.length == 0) {
        wx.showModal({
          title: '提示',
          content: '已经到底了',
        })
      }
      var list = that.data.orders.concat(data.body)
      that.setData({
        orders: list,
        offset: list.length
      })
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
  },
  refesh: function () {

  },
  loadMore: function () {
    this.requestGoods();
  },
  scroll: function (event) {
    //该方法绑定了页面滚动时的事件，我这里记录了当前的position.y的值,为了请求数据之后把页面定位到这里来。
    this.setData({
      scrollTop: event.detail.scrollTop
    });

  },
  add: function () {
    wx.navigateTo({
      url: '../add/add',
    })
  },
  modify: function () {

  },
  del: function (e) {
    var index = Number(e.currentTarget.dataset.index);
    console.log(index);
    var that = this;
    netUtils.sendRequest("seller/deleteGoodsByid.do",{goodsid:this.data.orders[index].goodsid},(data)=>{
      that.data.orders.splice(index,1);
      that.setData({orders:that.data.orders});
    })
  }
})